<template>
	<view>
		<view class="u-page">
			<u-list @scrolltolower="scrolltolower">
				<u-list-item v-for="(item, index) in company" :key="index">
					<u-cell value="选择" :title="`${item.name} `" isLink @click.stop="gohome(item)" :label="`${item.address}`">
					</u-cell>
				</u-list-item>
			</u-list>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				company: []
			}
		},
		methods: {
			gohome(item) {
				console.log(item)
				//切换到首页 保存用户信息
				// uni.navigateTo({
				// 	url: "/pages/index/index"
				// })
				this.$store.state.myCompanyId = item.id
				this.$store.state.myCompanyName = item.name
				this.$store.state.ownCompanyUserId = item.ownerUserId

				//查询在公司的基本信息
				var that = this
				this.api.post("/employee/myEmployeeByQuery", {
					companyId: item.id,
					userId: that.$store.state.userId
				}).then(res => {
					console.log(res.data.length)
					if (res.data.length != 0) {
						console.log(res.data[0].phone)
						console.log(res)
						that.$store.state.phone = res.data[0].phone
						that.$store.state.sex = res.data[0].sex
						that.$store.state.userNumber = res.data[0].userNumber
						that.$store.state.userType = res.data[0].userType
						that.$store.state.userName = res.data[0].userName
						that.$store.state.employeeId = res.data[0].id
					}

				})
			
				uni.showLoading({
					title: '加载中'
				});

				setTimeout(function() {
					uni.hideLoading();
					that.$store.commit("getUserInfo")
					
					uni.switchTab({
						url:"/pages/index/index"
					})
				}, 2000);



			}
		},
		onLoad() {
			var that = this
			this.api.get("/User/myCompanyByUserId/" + this.$store.state.userId, {}).then(res => {
				console.log(res)
				that.company = res.data
			})
		},

	}
</script>

<style>

</style>
